<?php

namespace Alipay\AlipayFund\Response;

use Alipay\Http\Response;

class AlipayFundAccountQueryResponse extends Response
{
    private $msg;

    private $availableAmount;

    private $freezeAmount;

    private $status;

    private $sign;

    public function resolve(): Response
    {
        parent::resolve();
        if (json_decode($this->getBody())) {

            $body = json_decode($this->getBody(), true);
            $this->setBody($body);
            $this->sign = $body['sign'] ?? '';
            $body = $body['alipay_fund_account_query_response'] ?? '';

            $this->availableAmount = $body['available_amount'] ?? '';
            $this->freezeAmount = $body['freeze_amount']?? '';

            $this->msg = $body['msg'] ?? '';
            $this->status = $body['status'] ?? '';

            $code = $body['code'] ?? '';
            if ($code != '10000') {
                $this->setError($this->msg . ($body['sub_code'] ?? '') . ($body['sub_msg'] ?? ''));
            }
        } else {
            $this->setError($this->getBody());
        }
        return $this;
    }

    /**
     * @return mixed
     */
    public function getMsg()
    {
        return $this->msg;
    }

    /**
     * @return mixed
     */
    public function getAvailableAmount()
    {
        return $this->availableAmount;
    }

    /**
     * @return mixed
     */
    public function getFreezeAmount()
    {
        return $this->freezeAmount;
    }


}